package client;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;

/**
 * @author yuzk
 * @date 2018/1/22
 */

public class MyWebSocketClient extends WebSocketClient {

    public MyWebSocketClient(URI serverUri) {
        super(serverUri);
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        send("Hello, it is me");
        System.out.println("connect open");
    }

    @Override
    public void onMessage(String s) {
        System.out.println("received : " + s);
    }

    @Override
    public void onClose(int i, String s, boolean b) {
        System.out.println("connect close");
    }

    @Override
    public void onError(Exception e) {
        System.out.println("occur error : " + e.getMessage());
    }

    public static void main(String[] args) throws Exception{
        MyWebSocketClient client = new MyWebSocketClient(new URI("ws://localhost:9999/ws"));
        client.connect();
    }
}
